<template>
	<view>
		<view class="text">
			<text>登录体验更多精彩</text>
		</view>
		<view class="text1">
			<text>未注册手机号登录后将自动创建账号</text>
		</view>
		<view class="uni-form-item uni-column">
			<u-input v-model="phone" type="type" placeholder="请输入手机号" />
			<u-input v-model="password" type="password" placeholder="请输入密码" />
		</view>

		<view class="button">
			<button @click="submit(user)">登录</button>
		</view>
	</view>
</template>
<script>
	// import {url} from '../../config/config.js'; 
	export default {
		data() {
			return {
				phone: '15171189697',
				password: 'htl240@0815',
				user: ''
			}
		},
		// onLoad() {
		// 	this.submit()
		// },
		methods: {

			//点击登录，验证有没有账号，能否登录，成功跳转到发现页
			submit(user) {
				const data = {
					phone: this.phone,
					password: this.password
				};
				uni.request({
					url: 'http://localhost:3000/login/cellphone',
					data: {
						phone: this.phone,
						password: this.password
					},
					success: (res) => {
						this.user = res.data.account.id
						if (res.data.account.id !== '') {
							uni.showToast({
								icon: 'none',
								title: '登录成功',
							});
							setTimeout(function() {
								uni.reLaunch({
									url: '../find/find'
								})
							}, 2000)
							uni.setStorageSync('setUser', res.data.account.id);
				            console.log(res.data.account.id)
						}
						if (res.data.account.id == '') {
							uni.showToast({
								icon: 'none',
								title: '登录失败',
							});
						}


					}
				})
				

			}
		}
	}
</script>

<style lang="scss">
	.text {
		margin-top: 150rpx;
		font-weight: 600;
		font-size: 16px;
		letter-spacing: 3px;
		margin-left: 10px;

	}

	.text1 {
		color: #bebebe;
		margin-left: 10px;
		margin-bottom: 60rpx;
	}

	.uni-column {
		margin-left: 10px;
		margin-bottom: 100rpx;
		border-bottom: 1px solid #dbdbdb;
		margin-right: 30px;
	}

	.button {
		width: 700rpx;
		margin-left: 26rpx;
	}

	button {
		border-radius: 40rpx;
		background: #CF3333;
		color: #fff;
		font-size: 30rpx;
	}
</style>
